package com.lire.shop.dao;

import com.lire.shop.entity.Order;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

@Repository
@Transactional
public interface OrderRepository extends JpaRepository<Order, Long> {

    @Query("select o from shop_order o where o.uid = :uid")
    List<Order> findAllByUid(@Param("uid") Long uid);

    @Modifying
    @Query("update shop_order  set orderStatus = :orderStatus where oid=:oid")
    int updateStatusById(@Param("orderStatus") Integer oStatus, @Param("oid") Long oid);


    Order findByOrderNumber(String orderNumber);
}
